<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            border-collapse: collapse;
            margin: 0 auto;
        }

        .head th {
            padding: 10px;
            color: aliceblue;
            background-color: deepskyblue;
            border: 1px solid deepskyblue;
        }

        .content td {
            padding: 10px 40px;
            border: 1px solid;
        }
    </style>
</head>

<body>
    <table>
        <tr class="head">
            <th><input type="checkbox" class="checkAll">全选</th>
            <th>商品</th>
            <th>商家</th>
            <th>价格</th>
        </tr>
        <tr class="content">
            <td><input type="checkbox" class="ck"></td>
            <td>小米手机</td>
            <td>小米</td>
            <td>&yen;1999</td>
        </tr>
        <tr class="content">
            <td><input type="checkbox" class="ck"></td>
            <td>小米净水器</td>
            <td>小米</td>
            <td>&yen;4999</td>
        </tr>
        <tr class="content">
            <td><input type="checkbox" class="ck"></td>
            <td>小米电视</td>
            <td>小米</td>
            <td>&yen;5999</td>
        </tr>
    </table>
    <script>
        const checkAll = document.querySelector('.checkAll')
        const cks = document.querySelectorAll('.ck')
        checkAll.addEventListener('click', function () {
            for (let i = 0; i < cks.length; i++) {
                cks[i].checked = this.checked
            }
        })
        for (let i = 0; i < cks.length; i++) {
            cks[i].addEventListener('click', function () {
                checkAll.checked = document.querySelectorAll('.ck:checked').length === cks.length
            })
        }
    </script>
</body>

</html>